Skip to content

Compiler #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2019
Merged

Compiler #29

merged 3 commits into from
Aug 12, 2019

Conversation

sanket1729
Copy link
Member

This will fail because it depends on other type check PR's to get in first.

@sanket1729 sanket1729 force-pushed the compiler-final branch 5 times, most recently from 41d3e41 to 0e7c4e3 Compare August 9, 2019 21:34
@sanket1729 sanket1729 changed the title Compiler final Compiler Aug 12, 2019
/// A Compilation key subtype of another if the type if subtype and other
/// attributes are equal
fn is_subtype(self, other: Self) -> bool {
return self.ty.is_subtype(other.ty)
Copy link
Member

Choose a reason for hiding this comment

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

nit: no need for return

#[derive(Copy, Clone, Debug)]
struct CompilerExtData {
pub struct CompilerExtData {
Copy link
Member

Choose a reason for hiding this comment

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

made public?

dissat_cost: Some(dissat_cost),
})
}
}

/// Miniscript AST fragment with additional data needed by the compiler
#[derive(Clone, Debug)]
struct AstElemExt<Pk: MiniscriptKey> {
pub struct AstElemExt<Pk: MiniscriptKey> {
Copy link
Member

Choose a reason for hiding this comment

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

made pub? and its fields?

pk_cost as f64
+ self.sat_cost * sat_prob
+ match (dissat_prob, self.dissat_cost) {
pub fn cost_1d(&self, sat_prob: f64, dissat_prob: Option<f64>) -> f64 {
Copy link
Member

Choose a reason for hiding this comment

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

made pub?

@sanket1729 sanket1729 force-pushed the compiler-final branch 2 times, most recently from 5b52579 to ca92df2 Compare August 12, 2019 20:56
@apoelstra apoelstra merged commit 5694ce5 into rust-bitcoin:master Aug 12, 2019
apoelstra added a commit that referenced this pull request May 20, 2025
In the compiler we have a function which inserts the "cast closure" of
an expression. It accepts the expression as a candidate as well as a
large list of cast-wrapped variants of the expression. For each
candidate it rejects it if it is consensus-invalid or has malleable
satisfactions.

In the original compiler (PR #29) it would decide whether an expression
was malleable by checking ty.mall.non_malleable on the miniscript. It
had the confusing comment "return malleable types directly" which I
believe was supposed to mean "return early if the node is malleable".
The comment also observes that "If a elem is malleable, all the casts to
it are also going to be malleable" but the code doesn't actually use
this fact anywhere. It always tries all the casts. But ok, whatever.

Later in #97 (add context to Miniscript) we weakened the malleability
check in a bizarre way -- now it checks that the node is malleable
according to the type system AND that it is non-malleable according to
the context system. That is, we whitelist or_i and d: as "acceptable
malleability" in a legacy/bare context.

This change, which was not commented on in the original PR, seems like
it's just totally wrong. I suspect it was supposed to be an or: if the
node is malleable according to the type system OR according to the
contextual checks, then skip it. But I'm unsure. (The check is also
wrong because the contextual check is wrong; see the last commit.)

Anyway, after some fairly heavy fuzzing I was unable to find any
instance where this check affects compiler output. I suspect that it's
merely an optimization. So change it back to the stronger, simpler check
and update the comment.
apoelstra added a commit to apoelstra/rust-miniscript that referenced this pull request Jun 20, 2025
In the compiler we have a function which inserts the "cast closure" of
an expression. It accepts the expression as a candidate as well as a
large list of cast-wrapped variants of the expression. For each
candidate it rejects it if it is consensus-invalid or has malleable
satisfactions.

In the original compiler (PR rust-bitcoin#29) it would decide whether an expression
was malleable by checking ty.mall.non_malleable on the miniscript. It
had the confusing comment "return malleable types directly" which I
believe was supposed to mean "return early if the node is malleable".
The comment also observes that "If a elem is malleable, all the casts to
it are also going to be malleable" but the code doesn't actually use
this fact anywhere. It always tries all the casts. But ok, whatever.

Later in rust-bitcoin#97 (add context to Miniscript) we weakened the malleability
check in a bizarre way -- now it checks that the node is malleable
according to the type system AND that it is non-malleable according to
the context system. That is, we whitelist or_i and d: as "acceptable
malleability" in a legacy/bare context.

This change, which was not commented on in the original PR, seems like
it's just totally wrong. I suspect it was supposed to be an or: if the
node is malleable according to the type system OR according to the
contextual checks, then skip it. But I'm unsure. (The check is also
wrong because the contextual check is wrong; see the last commit.)

Anyway, after some fairly heavy fuzzing I was unable to find any
instance where this check affects compiler output. I suspect that it's
merely an optimization. So change it back to the stronger, simpler check
and update the comment.
apoelstra added a commit to apoelstra/rust-miniscript that referenced this pull request Jun 20, 2025
In the compiler we have a function which inserts the "cast closure" of
an expression. It accepts the expression as a candidate as well as a
large list of cast-wrapped variants of the expression. For each
candidate it rejects it if it is consensus-invalid or has malleable
satisfactions.

In the original compiler (PR rust-bitcoin#29) it would decide whether an expression
was malleable by checking ty.mall.non_malleable on the miniscript. It
had the confusing comment "return malleable types directly" which I
believe was supposed to mean "return early if the node is malleable".
The comment also observes that "If a elem is malleable, all the casts to
it are also going to be malleable" but the code doesn't actually use
this fact anywhere. It always tries all the casts. But ok, whatever.

Later in rust-bitcoin#97 (add context to Miniscript) we weakened the malleability
check in a bizarre way -- now it checks that the node is malleable
according to the type system AND that it is non-malleable according to
the context system. That is, we whitelist or_i and d: as "acceptable
malleability" in a legacy/bare context.

This change, which was not commented on in the original PR, seems like
it's just totally wrong. I suspect it was supposed to be an or: if the
node is malleable according to the type system OR according to the
contextual checks, then skip it. But I'm unsure. (The check is also
wrong because the contextual check is wrong; see the last commit.)

Anyway, after some fairly heavy fuzzing I was unable to find any
instance where this check affects compiler output. I suspect that it's
merely an optimization. So change it back to the stronger, simpler check
and update the comment.
apoelstra added a commit to apoelstra/rust-miniscript that referenced this pull request Jun 20, 2025
In the compiler we have a function which inserts the "cast closure" of
an expression. It accepts the expression as a candidate as well as a
large list of cast-wrapped variants of the expression. For each
candidate it rejects it if it is consensus-invalid or has malleable
satisfactions.

In the original compiler (PR rust-bitcoin#29) it would decide whether an expression
was malleable by checking ty.mall.non_malleable on the miniscript. It
had the confusing comment "return malleable types directly" which I
believe was supposed to mean "return early if the node is malleable".
The comment also observes that "If a elem is malleable, all the casts to
it are also going to be malleable" but the code doesn't actually use
this fact anywhere. It always tries all the casts. But ok, whatever.

Later in rust-bitcoin#97 (add context to Miniscript) we weakened the malleability
check in a bizarre way -- now it checks that the node is malleable
according to the type system AND that it is non-malleable according to
the context system. That is, we whitelist or_i and d: as "acceptable
malleability" in a legacy/bare context.

This change, which was not commented on in the original PR, seems like
it's just totally wrong. I suspect it was supposed to be an or: if the
node is malleable according to the type system OR according to the
contextual checks, then skip it. But I'm unsure. (The check is also
wrong because the contextual check is wrong; see the last commit.)

Anyway, after some fairly heavy fuzzing I was unable to find any
instance where this check affects compiler output. I suspect that it's
merely an optimization. So change it back to the stronger, simpler check
and update the comment.
apoelstra added a commit to apoelstra/rust-miniscript that referenced this pull request Jun 21, 2025
In the compiler we have a function which inserts the "cast closure" of
an expression. It accepts the expression as a candidate as well as a
large list of cast-wrapped variants of the expression. For each
candidate it rejects it if it is consensus-invalid or has malleable
satisfactions.

In the original compiler (PR rust-bitcoin#29) it would decide whether an expression
was malleable by checking ty.mall.non_malleable on the miniscript. It
had the confusing comment "return malleable types directly" which I
believe was supposed to mean "return early if the node is malleable".
The comment also observes that "If a elem is malleable, all the casts to
it are also going to be malleable" but the code doesn't actually use
this fact anywhere. It always tries all the casts. But ok, whatever.

Later in rust-bitcoin#97 (add context to Miniscript) we weakened the malleability
check in a bizarre way -- now it checks that the node is malleable
according to the type system AND that it is non-malleable according to
the context system. That is, we whitelist or_i and d: as "acceptable
malleability" in a legacy/bare context.

This change, which was not commented on in the original PR, seems like
it's just totally wrong. I suspect it was supposed to be an or: if the
node is malleable according to the type system OR according to the
contextual checks, then skip it. But I'm unsure. (The check is also
wrong because the contextual check is wrong; see the last commit.)

Anyway, after some fairly heavy fuzzing I was unable to find any
instance where this check affects compiler output. I suspect that it's
merely an optimization. So change it back to the stronger, simpler check
and update the comment.
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