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

Use library to_hex function #573

Merged
merged 1 commit into from
Jan 25, 2023

Conversation

tcharding
Copy link
Member

We do not need to use the hex module from bitcoin_hashes to encode into hex, we have a function in this library.

Use library hex encoding logic, removes dependency on the hex module of bitcoin_hashes entirely from this crate.

@tcharding tcharding changed the title Use library to_hex function Use library to_hex function Jan 20, 2023
@tcharding
Copy link
Member Author

WTF ASAN issue here too now???

@tcharding
Copy link
Member Author

tcharding commented Jan 21, 2023

So it looks like the recent fix in rust-bitcoin worked because it stopped the memory sanitizer being run in a crate that depended on libc (i.e., only hashes not bitcoin). Since rust-secp256k1 depends on libc we are hitting the error again. Wrong, see comment below.

@tcharding
Copy link
Member Author

I hacked up a crate that uses rand as a dependency (because rand depends on libc) and the error is not hit. Adding a dependency on rust-secp256k1 (and a simple SecretKey usage) causes the error to be hit.

@tcharding
Copy link
Member Author

tcharding commented Jan 21, 2023

There is something strange going on, if we change (eckey_impl.h)

static int rustsecp256k1_v0_8_0_eckey_pubkey_parse(rustsecp256k1_v0_8_0_ge *elem, const unsigned char *pub, size_t size) {
    printf("\n\nsize: %d\n\n", size);

    if (size != 0) {
        return 0;
    }

The memory sanitizer errors for theif (size != 0) { line but the printf call is ok and size is equal to 33.

Function call stack:
PublicKey::from_slice -> ffi::secp256k1_ec_pubkey_parse -> rustsecp256k1_v0_8_0_ec_pubkey_parse -> rustsecp256k1_v0_8_0_eckey_pubkey_parse

@tcharding
Copy link
Member Author

I'm using this invocation to call ASAN and isolate the call path above.

CARGO_TERM_VERBOSE=true CC='clang -fsanitize=memory -fno-omit-frame-pointer' RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes' cargo +nightly test  -Zbuild-std --target x86_64-unknown-linux-gnu  public_key_from

@elichai
Copy link
Member

elichai commented Jan 22, 2023

That's very weird. valgrind doesn't complain about anything, I'm trying to delete more and more stuff to get a minimal reproducible example

@elichai
Copy link
Member

elichai commented Jan 22, 2023

Seems it is an LLVM bug: rust-lang/rust#107149
I also minimized the bug to this small example: https://github.com/elichai/msan_c_rust_bug

Adding -Cllvm-args=-msan-eager-checks=0 seems to solve this for now

@Kixunil
Copy link
Collaborator

Kixunil commented Jan 22, 2023

This one is in tests so no big deal, but I think this library should depend on bitcoin-internals and use hex impl from it, as well as various error handling stuff.

@apoelstra
Copy link
Member

@Kixunil libsecp has its own sha256 implementation. The dependency on bitcoin-hashes here is purely to get the ThirtyTwoByteHash trait, not to provide any funcitonality.

@Kixunil
Copy link
Collaborator

Kixunil commented Jan 23, 2023

LOL, I meant to write "hex impl"

apoelstra added a commit that referenced this pull request Jan 23, 2023
5a3f13e Overcome ASAN false positive regression (Tobin C. Harding)

Pull request description:

  The Memory Sanitizer is giving a false positive at the moment in `nightly`. Adding compiler flags resolves the issue. I didn't grok the exact root cause but this fixes it (cut'n'pasta from the issue [0]).

  Props to elichai for working this out: #573 (comment)

  [0] rust-lang/rust#107149

ACKs for top commit:
  apoelstra:
    ACK 5a3f13e

Tree-SHA512: 873145b732f7574c93ecc1bbabd9d82a1e501a39d1e2184770f71a07ffb72468783ab1b3fbfef8ef377c7e7a4b8c45253da1fce11660152d3369902136f1c049
@apoelstra
Copy link
Member

Oh, lol! That would make much more sense, given that there is no "hash impl" in bitcoin-internals.

Having said this, I don't really like the idea of there being a non-optional dependency on a perma-unstable crate, even if it's one that we maintain. If we got more than just hex decoding from it maybe.

We do not need to use the `hex` module from `bitcoin_hashes` to encode
into hex, we have a function in this library.

Use library hex encoding logic, removes dependency on the `hex` module
of `bitcoin_hashes` entirely from this crate.
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK bdfa0ff

@apoelstra apoelstra merged commit 92c4923 into rust-bitcoin:master Jan 25, 2023
@Kixunil
Copy link
Collaborator

Kixunil commented Jan 26, 2023

If we got more than just hex decoding from it maybe.

I think some error stuff as well.

@tcharding tcharding deleted the 01-21-rm-to-hex branch February 21, 2023 03:30
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.

4 participants