Skip to content
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

PSBT comparison problems #4752

Merged

Conversation

niftynei
Copy link
Collaborator

@grubles found a bug where our PSBT 'is identical' code was failing -- the updated version included a witness script, whereas the original did not. libwally pushes a type-byte onto the serialized version if there's any bytes at all -- setting the bytes to null avoids this.

@niftynei niftynei added this to the v0.10.2 milestone Aug 31, 2021
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Ack ad1bd9d

Minor change to remove ctx arg only.

Comment on lines 495 to 497
bool psbt_contribs_changed(const tal_t *ctx,
struct wally_psbt *orig,
struct wally_psbt *new)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an antipattern! It doesn't return an allocated object, so why pass in a ctx?

I think you meant to use tmpctx internally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ACK, yes i can do that. Since this is common it seems .. better? to use an internal allocation/free cycle -- is that the wrong intuition?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, tmpctx is pretty universal now. Either way.

Also remove all the unused code (checking for differences for a side
etc)
Otherwise libwally pushes the psbt-key for 'witness script' onto the
serialized version and we fail the 'is this identical' check.

Relevant line from libwally, where if bytes, we push a psbt_key.

```
static void push_typed_varbuff(unsigned char **cursor, size_t *max,
                               uint64_t type,
                               const unsigned char *bytes, size_t bytes_len)
{
    if (bytes) {
        push_psbt_key(cursor, max, type, NULL, 0);
        push_varbuff(cursor, max, bytes, bytes_len);
    }
}
```

Reported-By: @grubles
Changelog-Fixed: openchannel_signed would fail on PSBT comparison of materially identical PSBTs
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Ack 1fb4e58

* @new - 'updated' psbt, to verify is unchanged
*/
bool psbt_contribs_changed(struct wally_psbt *orig,
struct wally_psbt *new);
Copy link
Contributor

Choose a reason for hiding this comment

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

These should also be const struct wally_psbt, no?

@cdecker cdecker merged commit 0f05238 into ElementsProject:master Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants