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

update vendored libsecp to 0.3.2 #645

Closed

Conversation

apoelstra
Copy link
Member

@apoelstra apoelstra commented Aug 16, 2023

Fixes #631.

Also bumps the major version of rust-secp256k1-sys since this bump involves renaming all the symbols, so we might as well do it now. But we won't release after this PR; will wait until we're sure we're ready to do the release.

To reproduce run

./vendor-libsecp.sh acf5c55ae6a94e5ca847e07def40427547876101

@apoelstra
Copy link
Member Author

CI failure is because we have a test_raw_ctx which is double-dropping context objects. In #261 where we introduced the double-drop I claimed that the first one "was a no-op, which is the point of the test". I need to investigate whether this used to be true and when it stopped being true..

upstream libsecp now has a CMakeLists.txt file. Many years ago we added
some things to .gitignore which appear to be local developers committing
the names of their own stray files, and now this is causing the
revendoring script to lose track of vendored files.
This is just a bad test. It constructs a preallocated context object by
starting from a non-preallocated context object, in a way that can't be
done by users (since it directly constructs a `Secp256k1` struct) and a
way that is very difficult to unwind, because you wind up with two
pointers to the same underlying context object, one a "preallocated" one
and one a normal one.

If you then drop the preallocated one, it will call
`secp256k1_context_destroy`, forcing you to manually deallocate the
other one. If you drop the normally-allocated one, you need to
mem::forget the preallocated one to avoid calling
`secp256k1_context_destroy` twice. The whole thing is pretty fragile.

There is another unit test, `test_raw_ctx`, which gets into the same
situation but using the public API, and demonstrates a few ways to get
out of it.
I'm not sure how these came to be committed, but they shouldn't be.
Running the vendoring script results in them being deleted.
@apoelstra
Copy link
Member Author

Should be good to go. This wound up being more involved than I expected. Upstream changed the semantics of secp256k1_preallocated_context_destroy so that you can't call it twice in a row anymore which exposed some weirdness in our unit tests.

@tcharding tcharding mentioned this pull request Aug 17, 2023
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Light review, I didn't verify the changes to depend, assuming they are done mechanically. Also I did not fully grok the ManuallyDrop unit test changes. I don't claim to be an unsafe code reviewer at the moment and did not allocate clock cycles to understanding this particular thing fully.

| grep "SIGILL\\|\[libsecp256k1] illegal argument. !rustsecp256k1_v0_._._fe_is_zero(&ge->x)"
| grep "SIGILL\\|\[libsecp256k1] illegal argument. "
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? It works still, right? You just don't like the grep statement?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the assertion has changed in the latest version of libsecp.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, cool. Thanks.

Comment on lines +589 to +590
// The following drop will have no effect; in fact, they will trigger a compiler
// error because manually dropping a `ManuallyDrop` is almost certainly incorrect.
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to write "will trigger a clippy warning"?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, in 1.72 and higher it will be a compiler warning.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, my bad.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 186b643

@tcharding
Copy link
Member

We want to get this in before release, right?

tcharding added a commit to tcharding/rust-secp256k1 that referenced this pull request Aug 24, 2023
If rust-bitcoin#645 merges we will need a release of `secp256k1-sys` as well.
@sanket1729
Copy link
Member

Can you also add how to reproduce this in the commit message? Would help me review. I think the vendoring scripts now have some env variables that I need to set to reproduce.

@apoelstra
Copy link
Member Author

@sanket1729 put a command in the commit description.

@tcharding
Copy link
Member

Gentle bump please crew.

tcharding added a commit to tcharding/rust-secp256k1 that referenced this pull request Sep 3, 2023
If rust-bitcoin#645 merges we will need a release of `secp256k1-sys` as well.
@tcharding
Copy link
Member

Do we want to jump straight to v0.4.0?

@apoelstra
Copy link
Member Author

@tcharding yeah, let's do it.

Can you open such a PR? You may want to copy the patch files from this one. (If not I can do it, just let me know. Normally it's a straightforward process of just running the vendoring script, but if the patches no longer apply it can be a bit thorny.)

@Davidson-Souza
Copy link
Contributor

+1 on bumping to v0.4.0. Since this release is the only one with the EllSwift module, needed for #627.

@tcharding
Copy link
Member

Yep no sweat I can do it.

@tcharding
Copy link
Member

I just realized that releasing with libsecp 0.4.0 is not trivial because we need to write the wrappers for the new EllSwift stuff, given that (and the fact that I can't satisfy the linker in #652) as well as the fact that we are behind schedule on the rust-bitcoin release can we merge and release using this PR and then do libsecp 0.4.0 upgrade straight after release?

@Davidson-Souza
Copy link
Contributor

@tcharding

we need to write the wrappers for the new EllSwift stuff

Technically, the code exists (#627). But it needs to be reviewed, and may require changes after #652

@tcharding
Copy link
Member

Oh my bad, I did not realise. Will have another go, thanks.

apoelstra added a commit that referenced this pull request Sep 30, 2023
80b2a8d Update vendored libsecp to v0.4.0 (Davidson Souza)
d2285c9 ci: Remove MIPS* from CI (Davidson Souza)
0d58f50 ci: generalize grp in "illegal callback" test (Andrew Poelstra)
acf9ac1 delete `test_manual_create_destroy` test (Andrew Poelstra)
04ce508 lib: fix bad unit test (Andrew Poelstra)
e4cca90 gitignore: remove things that shouldn't be there (Andrew Poelstra)

Pull request description:

  Replaces  #645 and #652. Precedes #627.

  I'm basically using #652 but resolving the linking problems,

  My local CI is erring on windows cross-test, but I can compile without issue with `cargo build --target x86_64-pc-windows-gnu`. Some MIPS jobs failed before even installing cross, I think those aren't really related to this PR. Any ideas on what can be happening?

ACKs for top commit:
  apoelstra:
    ACK 80b2a8d

Tree-SHA512: 62c2e04348110e3995111fa666f10dcc403b963770d047361f9209cf45b45db8744a7eb6d9ee3278d18007412dab5131ac3e1dd3e3d704963c6a6f232d57199a
@tcharding
Copy link
Member

We can close this one now.

@apoelstra apoelstra closed this Oct 2, 2023
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.

Update secp256k1 C dependency to 0.3.1
4 participants