Skip to content

smite-ir: split determinism out of has_side_effects - #198

Open
devvaansh wants to merge 1 commit into
lnfuzz:masterfrom
devvaansh:operation-is-deterministic
Open

smite-ir: split determinism out of has_side_effects#198
devvaansh wants to merge 1 commit into
lnfuzz:masterfrom
devvaansh:operation-is-deterministic

Conversation

@devvaansh

@devvaansh devvaansh commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #155, where we agreed LookupShortChannelId doesn't really have side effects and that CSE wants a separate question answered.

has_side_effects was being asked three different questions by three callers: DCE wants to know whether an instruction can be dropped, CSE wants to know whether two instructions can be merged, and InstructionReorderMutator wants to know whether an instruction's position matters. Those coincide for every operation we had until LookupShortChannelId, which is read-only but reads chain state, so it was marked as side-effecting to keep CSE away from it.

Add depends_only_on_inputs, and is_pure on top of it, so each caller asks what it actually means. DCE keeps using has_side_effects, while CSE and the reorder mutator switch to is_pure. LookupShortChannelId becomes side-effect free, and it joins CreateFundingTransaction, SendFundingCreated, and the Recv operations in reading state beyond its inputs.

The only behavior change is that DCE can now drop a LookupShortChannelId whose result nothing consumes. I checked every operation, and it is the only one where !is_pure() differs from has_side_effects(), so CSE's skip set and the reorder mutator's candidate set are unchanged.

Keeping the lookup reorderable matters: moving it across a MineBlocks is what turns a confirmed short_channel_id into the unconfirmed sentinel, and it's the only way to reach the sentinel in a program whose scid comes from a lookup. Marking it pure would have silently removed that, so there's a test covering it along with tests for the CSE and DCE behavior.

Ref: #155

@devvaansh
devvaansh force-pushed the operation-is-deterministic branch 2 times, most recently from ef5f24c to 9b4dcf2 Compare August 10, 2026 19:34
Comment thread smite-ir/src/operation.rs Outdated
| Self::LookupShortChannelId => true,
Self::LoadAmount(_)
| Self::BroadcastTransaction => true,
Self::LookupShortChannelId

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.

Let's keep the match arms in the same order as the operator definitions. Applies throughout this file.

BTW, the LookupShortChannelId definition is currently under the "Act" header comment -- we should move it to its own new section.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done -- moved LookupShortChannelId under a new // -- Query: read state from outside the program -- section, and fixed the ordering throughout the file.

Comment thread smite-ir/src/operation.rs Outdated
/// CSE even when it is free of side effects, and its position in the
/// program is meaningful.
#[must_use]
pub fn is_deterministic(&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.

I think deterministic actually isn't the right word. What we're checking is that the operation depends only on its inputs (not some external state).

Maybe depends_only_on_inputs would be better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, renamed to depends_only_on_inputs

Comment thread smite-ir/src/operation.rs Outdated
| Self::RecvChannelReady => false,
Self::SendMessage
| Self::SendOpenChannel
| Self::SendFundingCreated

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.

SendFundingCreated actually depends on executor state, so it should be in the false category.

@devvaansh
devvaansh force-pushed the operation-is-deterministic branch from 9b4dcf2 to 29cd0c2 Compare August 11, 2026 22:19
LookupShortChannelId is a read-only operation, but it was marked as having
side effects to stop CSE from merging two lookups whose results differ.
Add depends_only_on_inputs and is_pure so CSE and the reorder mutator can
ask about purity while DCE keeps asking about side effects.
@devvaansh
devvaansh force-pushed the operation-is-deterministic branch from 29cd0c2 to 4dcce5e Compare August 11, 2026 22:28
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