-
Notifications
You must be signed in to change notification settings - Fork 122
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
Elligator swift encoding #737
Conversation
One more thing you'll need to be able to communicate with the Bitcoin Core TP... I changed the protocol name to |
fa73f14
to
12356bd
Compare
encrypted_static_pub_k[..32].copy_from_slice(&static_pub_k[..32]); | ||
// 5. appends `EncryptAndHash(s.public_key)` (64 bytes encrypted elligatorswift public key, 16 bytes MAC) | ||
let mut encrypted_static_pub_k = vec![0; ELLSWIFT_ENCODING_SIZE]; | ||
let elligatorswift_ours_static = ElligatorSwift::from_pubkey(self.s.public_key()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to get the EllSwift encoded key directly from the private key?
That might be a bit faster. Though performance is not a big deal here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can derive the Ellswift pubkey from the private key. Moreover, in the SRI internal representation of Initiator and Responder handshake roles it is possible to store only the private key and derive whatever we want from that. This goes even further.
I am not totally against it, but I would prefer to convert the public key instead for two reasons
- because it resembles more the idea that then Ellswift is just an encoding
- I would like to think about it, test it and generally be more conservative an proceed by steps
What do you think about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong preference.
Tested that this works against https://github.com/Sjors/bitcoin/tree/2024/02/sv2-poll-ellswift Left some cosmetic comments above. It should now be possible to simplify |
@lorbax based on discussion in stratum-mining/sv2-spec#66 (comment) I changed the protocol name to However, in order not to break your pull request here, I temporarily added a revert commit which keeps the old protocol name Let me know when you've had a chance to change the protocol name here, and I'll drop that commit. |
Bencher
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
Bencher
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
Bencher
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
Bencher
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
fixed history and force-pushed |
I don't think "most tests pass" and "compiles but doesn't work" are useful commit names. I think two commits should be enough:
|
@Sjors I will do it today |
There's also one failing test: https://github.com/stratum-mining/stratum/actions/runs/7856601115/job/21439624655?pr=737#step:7:746 |
It's because on our VPS is currently running the |
cfcb638
to
109f233
Compare
Tested 109f233 (with #747 cherry picked) against the template provider Code looks correct too. Minor nit: the @Fi3 / @jakubtrnka can you give it a code review as well?
Once this is merged I plan to update |
@Sjors restored cargo lock in utils |
7d342fd
to
1c42de9
Compare
@@ -10,6 +10,7 @@ repository = "https://github.com/stratum-mining/stratum" | |||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |||
|
|||
[dependencies] | |||
secp256k1 = { version = "0.28.2", default-features = false, features =["hashes", "alloc","rand","rand-std"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems that you can remove this dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this?
pub const ELLSWIFT_ENCODING_SIZE: usize = secp256k1::constants::ELLSWIFT_ENCODING_SIZE;
I thought it would have been a good idea to keep this constant depending from the one in secp256kq (it is what I meant when I added it in the toml, but later I forgot).
Otherwise, just
pub const ELLSWIFT_ENCODING_SIZE: usize = 64;
without calling secp256k1 library.
roles/jd-client/Cargo.toml
Outdated
@@ -29,4 +29,4 @@ tracing-subscriber = { version = "0.3" } | |||
error_handling = { version = "0.1", path = "../../utils/error-handling" } | |||
nohash-hasher = "0.2.0" | |||
key-utils = { version = "^1.0.0", path = "../../utils/key-utils" } | |||
secp256k1 = { version = "0.27.0", default-features = false, features =["bitcoin_hashes","alloc","rand","rand-std"] } | |||
secp256k1 = { version = "0.28.2", default-features = false, features =["alloc","rand","rand-std"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should put it in the stratum-common crate and import secp256k1 everywhere from there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking also that using secp256k1 in the roles is not the best thing. This logic should stay in roles-logic-sv2 or key-utils. But I guess that this will be better suited for a new PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked that sepc256k1
in roles is used in
- jd-server for signing the tokens
- pool to verify tokens
So I think that it is unavoidable importing there. Btw it is not used in any other role (and therefore I can remove it from the jd-client dependencies).
I also agree that we should put secp256k1
in stratum common import from there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested 1c42de9. Only difference with my last review is in a Cargo.lock file.
Use ElligatorSwift encoding for representations of public keys and the related ECDH procedure For serializing and deserilizing the messages sxchanges during the handshake is made use of constants for lenghts of message chunks change protocol name for encryption New protocol name "Noise_NX_Secp256k1+EllSwift_ChaChaPoly_SHA256" downstream_sv1::diff_management::test::test_converge_to_spm_from_low downstream_sv1::diff_management::test::test_diff_management fail non-deterministically On top of https://github.com/GitGab19/stratum/tree/fix-empty-mempool
in jd-client role was imported secp256k1 library, but wasn't used in that crate.
9194e57
to
b6008d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the rebase, ACK b6008d4
ElligatorSwift encoding for pubkeys in handshake operations.
This branch must be tested with thev new TP by @Sjors.
Already tested in regtest. Needs to be tested in testnet.