Repository navigation
refactor(compile): extract unspendable key derivation - #368
vadim-anfv wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #368 +/- ##
==========================================
+ Coverage 59.08% 59.51% +0.42%
==========================================
Files 25 26 +1
Lines 4646 4695 +49
==========================================
+ Hits 2745 2794 +49
Misses 1901 1901
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Move the H + rG derivation out of the compile handler into new module, so that the verification that pairs with it can share it. The derivation itself is unchanged.
Check that a tr() descriptor's internal key is the NUMS point tweaked by a given r, so the r that compile returns can be checked against the descriptor. No caller yet: the CLI surface is undecided, hence the dead_code allow.
0970734 to
3339960
Compare
bvotteler
left a comment
There was a problem hiding this comment.
tACK 3339960
Confirmed all tests pass at merge base as well as at HEAD, using just test.
compilebehaves as before, the existingtest_compile_*tests pass untouched
Confirmed test_compile behaves as before, also ran taproot tests and found expected behavior.
taproot and test_compile runs & results
At HEAD (commit: 3339960):
$ cargo test --features compiler -- taproot test_compile
[..]
# taproot summary:
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 16 filtered out; finished in 0.00s
[..]
# test_compile summary:
test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 16 filtered out; finished in 0.05sAt merge base,git switch --detach HEAD~2 (commit 4dbc3e8):
$ cargo test --features compiler -- taproot test_compile
[..]
# taproot summary:
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 16 filtered out; finished in 0.00s
[..]
# test_compile summary:
test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 16 filtered out; finished in 0.04sConfirmed expectations:
- Visually confirmed individual tests for
test_compileare the same - 5 new
taproottests atHEAD - all tests passing
|
Concept ACK The direction of extracting the unspendable-key derivation logic and adding verification for the generated key and randomness pair makes sense. This builds naturally on PR #225, which introduced randomized key generation and exposed the randomness factor. I am currently reviewing the implementation and tests. |
|
ACK 3339960 I fetched the PR locally and built it with I compared the removed inline derivation in I also ran |
| } | ||
|
|
||
| /// Extract the internal key of a `tr()` descriptor. | ||
| #[allow(dead_code)] |
There was a problem hiding this comment.
nit: You can remove this; the code compiles without it since this function is called in the verify_unspendable_internal_key function, which itself has a #[allow(dead_code)] flag.
| const NUMS_UNSPENDABLE_KEY_HEX: &str = | ||
| "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"; | ||
|
|
||
| pub fn generate_unspendable_internal_key() -> Result<(XOnlyPublicKey, SecretKey), Error> { |
There was a problem hiding this comment.
nit: Since you added doc comments (///) for other functions, I am thinking you should do so for this function too.
There was a problem hiding this comment.
Nit (non-blocking): verify_unspendable_internal_key is called by the four tests and taproot_internal_key by the first in mod tests. Both #[allow(dead_code)]s can go if the two functions move into the test module:
#[cfg(test)]
mod tests {
use super::*;
// other imports
/// Check that the internal key of a `tr()` descriptor is the NUMS point tweaked by `r`.
fn verify_unspendable_internal_key(descriptor: &str, r: &SecretKey) -> Result<(), Error> {
if derive_unspendable_internal_key(r)? != taproot_internal_key(descriptor)? {
return Err(Error::UnspendableKeyMismatch);
}
Ok(())
}
/// Extract the internal key of a `tr()` descriptor.
fn taproot_internal_key(descriptor: &str) -> Result<XOnlyPublicKey, Error> {
...
}
// existing consts and tests
}|
Moving this to draft. As agreed in #218, it will also put I'm letting #378 go first, so it doesn't have to be reworked for the rename. And since the restructure is breaking, it can only be merged after 4.1.0 is released. @bvotteler @Musab1258 @emma31-dev thanks for the reviews, sorry for the churn. |
Description
Blocked by #378, see #368 (comment).
Continues #218.
compile --type trreturns therit derived the unspendable internal key from (#225); this adds the check that the pair holds, and extracts the derivation so both halves share it.The CLI surface is not part of this PR: the options are laid out in #218 (comment), and the logic is the same under all of them. Once we pick one, I'll open a follow-up PR wiring verification into the CLI, with integration tests.
Notes to the reviewers
compilebehaves as before, the existingtest_compile_*tests pass untouched#[allow(dead_code)]is there because nothing calls the verification until the command exists, and goes away with itrin a type, and left it as plain functions until the command adds more callersChecklists
All Submissions:
cargo fmtandcargo clippybefore committing