rust-simplicity icon indicating copy to clipboard operation
rust-simplicity copied to clipboard

Encoded program cannot be decoded

Open uncomputable opened this issue 7 months ago • 4 comments
trafficstars

Calling encode_to_vec and then RedeemNode::decode on the following program leads to a type unification error.

See https://github.com/BlockstreamResearch/simfony/issues/118

Decode(Type(Bind { existing_bound: { tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × ({ tmr: fd75bcd8cb55a5e424e09288ac8eb42942534ec1099b72bece0ea2c5479bf3e7, bit_width: 64, bound: 2^64 } × (... × ...))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))), new_bound: { tmr: 50b38cd76475ff8929288bfcd0d9df0e4a241c0a5708572ad264192a4fe67bee, bit_width: 0, bound: 1 }, hint: "comp combinator: left target = right source" }))

The Simplicity program is obtained by compiling the following Simfony 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));
}

Calling encode_to_vec yields the following hex string (unpruned, without debug symbols):

e2a4d900000000022c8000000041805481420c31206b1566dc41180459000000010342c80000000c1a82a40a05bf203601acfc10c13481c040e0027063f0c040b480a0dc170601903888

The fact that the encoding is broken makes it hard to describe the problematic Simplicity program in this issue. For now, the Simfony compiler must be used to obtain it.

For now, the code to reproduce the error lives on this Simfony branch. Run cargo test --all-features.

uncomputable avatar Apr 05 '25 06:04 uncomputable