-
Notifications
You must be signed in to change notification settings - Fork 281
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
This lib, and bitcoin_hashes, should have a cfg
param for logging everything that it does
#495
Comments
If this is going to be feature gated and only used during debugging then is it ok to add dependencies and use a logging framework? |
@tcharding yes, but I have no idea how to gate dependencies on |
Use an optional dependency and enable it by the feature, right? |
I hacked up a demo in #498 |
We definitely cannot use cargo features for this because it would make it too easy to turn on accidentally (or too easy for a malicious dependency to turn on). It will also make |
What did you have in mind? A custom configuration conditional (like we do for bench) suffers the same easy attackability as a normal configuration conditional. I can't think of any other way to use cargo that does not suffer the same weakness? |
It doesn't. You can't set a cfg flag by accident, and it's not obvious to me that you can set it at all from a dependency. But merely avoiding the accidental cases is reason enough not to use cargo features. |
Ok, I'm convinced that if we use a custom config option "logging" a malicious dependency cannot turn it on. To convince myself I created crates
I turned on logging |
Woke up last night thinking about this. I don't know exactly how
I don't know how |
If this is possible it sounds like a bug in cargo that dependencies can have non-local effects on each other like this. But I don't know if it's possible.
I don't think so. Can you make dependencies be gated on a RUSTFLAGS option? |
Oh sick, TIL! check this out: [target.'cfg(demo)'.dependencies]
log = "0.4" |
Nice! Let's do it. |
Can I clarify please, based on this comment being posted after the one above we are not going to use the |
@tcharding sorry to be inconsistent! After seeing your two attempts, I prefer avoiding the |
No sweat, cheers. |
We should have a
cfg
flag, which if set alongside an environment variableCRYPTO_DEBUG_FILE
or something, logs all actions to that file. Meaning, at the very least:Obviously this would be extremely unsafe and the cfg flag should be named
danger_leak_secret_data
or something long and scary, but it would be really helpful when debugging higher level crypto protocols (which seem to always fail in the form of "this uniformly random number does not equal this other uniformly random number") it would be extremely helpful for figuring out what went wrong.For rust-secp-zkp it may also make sense to instrument the C code, since there are much more complicated crypto algos there, but as a first step just logging the inputs and outputs of the API-level functions would give us a ton of information about why, e.g. transaction signatures aren't passing.
We could require a high MSRV and
std
for this feature to work, so we could just have astatic LOGFILE: Mutex<fs::File>
as the log sink and not need any unsafe code or extra deps.cc @rustyrussell who suggested this to me..
The text was updated successfully, but these errors were encountered: