Skip to content

TypeInferenceUnification error when unpacking two pairs #114

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

Closed
m-kus opened this issue Mar 19, 2025 · 10 comments · Fixed by BlockstreamResearch/rust-simplicity#281 or #116
Closed

Comments

@m-kus
Copy link
Contributor

m-kus commented Mar 19, 2025

I get TypeInferenceUnification error when trying to run the following program:

fn main() {
    let (a, b): (u32, u32) = (0, 1);
    assert!(jet::eq_32(a, 0));

    let (c, d): (u32, u32) = (2, 3);
    assert!(jet::eq_32(c, 2));
    assert!(jet::eq_32(d, 3));
}

This does not reproduce in BitMachine (I suppose because it does not run type checking?) but only when using https://github.com/BlockstreamResearch/rust-simplicity/blob/33b043f9a153f0d7be82dee8fbd61179ad63b888/simplicity-sys/src/tests/mod.rs#L113 (which calls the same code as Elements node under the hood).

When I'm trying to disassemble I get:

Error: failed to decode program: failed to apply bound1to existing bound2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (2^64 × (... × ...))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))): comp combinator: left target = right source

@uncomputable
Copy link
Collaborator

Interesting. I couldn't reproduce the error on the Simfony IDE, but that website is running an older version. I will try the latest version next.

@m-kus
Copy link
Contributor Author

m-kus commented Mar 20, 2025

Ok thanks! I'm using this cli tool, in case it might be handy:

cargo install --git https://github.com/keep-starknet-strange/stark-symphony --rev d552969f2c64ce9fa80dc6a45bab17a4f6204bc9 simfony-cli

Then to build & run:

simfony run main.simf
simfony build main.simf --output-format simpl

uncomputable added a commit to uncomputable/simfony that referenced this issue Mar 20, 2025
@uncomputable
Copy link
Collaborator

I could reproduce the error using your stark-symphony crate.

This bug might be related to issues on Windows (BlockstreamResearch/rust-simplicity#274) or issues with values (BlockstreamResearch/rust-simplicity#275).

I am debugging and I will publish a new version of Simfony once I'm done. I will include a unit test with your program to prevent future regression.

@apoelstra
Copy link
Contributor

I think this might fix it in rust-simplicity -- it fixes a regression I found in the padded bit iterator of Value. It's hard for me to go further because I need to backport BlockstreamResearch/rust-simplicity#271 so that I stop crashing the release version :)

diff --git a/src/value.rs b/src/value.rs
index 3aea277..0d58f81 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -358,10 +358,10 @@ impl Value {
         let total_width = cmp::max(inner.ty.bit_width(), right.bit_width());

         let (concat, concat_offset) = product(
-            Some((&inner.inner, inner.bit_offset)),
-            inner.ty.bit_width(),
             None,
             total_width - inner.ty.bit_width(),
+            Some((&inner.inner, inner.bit_offset)),
+            inner.ty.bit_width(),
         );
         let (new_inner, new_bit_offset) = right_shift_1(&concat, concat_offset, false);
         Self {

@uncomputable
Copy link
Collaborator

I feel we should merge the change into the upstream repo, so I can update simfony. See BlockstreamResearch/rust-simplicity#281

uncomputable added a commit to uncomputable/simfony that referenced this issue Mar 22, 2025
uncomputable added a commit to uncomputable/simfony that referenced this issue Mar 22, 2025
@apoelstra
Copy link
Contributor

Yep, for sure! Was just posting the code here because I had to run, this was a somewhat-related open tab, and I didn't want to lose track of it. Thanks for opening the PR for me.

apoelstra added a commit to BlockstreamResearch/rust-simplicity that referenced this issue Mar 24, 2025
4b83c05 fix: Sum value regression (Christian Lewe)

Pull request description:

  Fixes #275

  I tried the fix [that was recommended](BlockstreamResearch/simfony#114 (comment)) on the Simfony crate and it made all examples pass.

ACKs for top commit:
  apoelstra:
    ACK 4b83c05; successfully ran local tests

Tree-SHA512: aa6710bd7ab1333bc17cec8a57297ca5c455904dea5bab59c01ac3fe37f9109dbd2d231e567e7510513dc2c9a2935f12dbd93a4a9e2d2aa29964a7d4727a86fb
@apoelstra
Copy link
Contributor

Reopening since it's apparently not fixed.

@apoelstra apoelstra reopened this Mar 24, 2025
@uncomputable
Copy link
Collaborator

uncomputable commented Mar 25, 2025

As far as Simfony is concerned, the bug is fixed. There is a passing unit test for this in the library.

@m-kus please reconfirm or correct me if I'm wrong.

uncomputable added a commit to uncomputable/simfony that referenced this issue Mar 25, 2025
@m-kus
Copy link
Contributor Author

m-kus commented Mar 25, 2025

@uncomputable there seems to be two related problems disguising as one, let's close this issue and I'll create a new one if that works better

I created #117 to showcase the remaining problem (tbh I'm not fully sure it's on the Simfony side) and new issue #118

@apoelstra
Copy link
Contributor

Thanks -- let's move to the other issue.

uncomputable added a commit to uncomputable/simfony that referenced this issue Mar 28, 2025
apoelstra added a commit that referenced this issue Mar 31, 2025
0a974f1 ci: Run tests on other platforms (Christian Lewe)
fb4a1d3 test: Check type error (Christian Lewe)
0dd62d2 feat: Support Apple silicon in flake (Christian Lewe)
c4832fe fix: Prune test programs (Christian Lewe)
826351c chore: Keep elements::Locktime prefix (Christian Lewe)
854db1a chore: Use bundled hex crate (Christian Lewe)
b3565e1 chore: Update rust-simplicity (Christian Lewe)
c8e2565 chore: Bump MSRV to 1.78.0 (Christian Lewe)

Pull request description:

  Update rust-simplicity to the latest version. This brings support for Mac and optimizations of the internal representation of Simplicity values. CI is enabled for Mac.

  Fixes #114

ACKs for top commit:
  apoelstra:
    ACK 0a974f1; successfully ran local tests

Tree-SHA512: 50fabfa67e5539d552cd18435690aa23a4791e1188adb378853291c3c661253c4bdd48506e8603d9ecc4e20d73ace50f3a7dff81ed3317661aee35b68114b14a
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 a pull request may close this issue.

3 participants