Skip to content

Noise-sv2 hardening - #706

Open
bit-aloo wants to merge 3 commits into
stratum-mining:mainfrom
bit-aloo:2026-08-09-noise-hardening-update
Open

Noise-sv2 hardening #706
bit-aloo wants to merge 3 commits into
stratum-mining:mainfrom
bit-aloo:2026-08-09-noise-hardening-update

Conversation

@bit-aloo

@bit-aloo bit-aloo commented Aug 9, 2026

Copy link
Copy Markdown
Member

@bit-aloo bit-aloo changed the title Noise-sv2 hardening update companion Noise-sv2 hardening Aug 9, 2026

@GitGab19 GitGab19 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clanker review:

Review findings

try_write_frame() can desynchronize the Noise transport

try_write_frame() encrypts the frame before calling try_write().

Encryption advances the Noise nonce. If the socket returns WouldBlock, the method returns Ok(false) but discards both the ciphertext and the consumed frame. The next frame then uses a later nonce while the peer is still expecting the discarded one, permanently desynchronizing the connection.

Partial writes have a similar problem: a ciphertext prefix may reach the socket while the remainder is discarded.

This behavior predates this PR, but it is directly relevant to the transport-state hardening. The write half should retain pending ciphertext and its write offset until the complete encrypted frame has been sent.

Add direct coverage for the split transport transition

The migration to separate TransportEncryptState and TransportDecryptState appears correct, but there is no focused test covering it.

A bidirectional client/server test should complete the handshake and exchange multiple frames concurrently. This would protect against swapped transport states, incorrect nonce progression, and regressions in future refactors.

@bit-aloo

Copy link
Copy Markdown
Member Author

Clanker review:

Review findings

try_write_frame() can desynchronize the Noise transport

try_write_frame() encrypts the frame before calling try_write().

Encryption advances the Noise nonce. If the socket returns WouldBlock, the method returns Ok(false) but discards both the ciphertext and the consumed frame. The next frame then uses a later nonce while the peer is still expecting the discarded one, permanently desynchronizing the connection.

Partial writes have a similar problem: a ciphertext prefix may reach the socket while the remainder is discarded.

This behavior predates this PR, but it is directly relevant to the transport-state hardening. The write half should retain pending ciphertext and its write offset until the complete encrypted frame has been sent.

Add direct coverage for the split transport transition

The migration to separate TransportEncryptState and TransportDecryptState appears correct, but there is no focused test covering it.

A bidirectional client/server test should complete the handshake and exchange multiple frames concurrently. This would protect against swapped transport states, incorrect nonce progression, and regressions in future refactors.

For first, as its predates this PR, I would open an issue for that and for second one, I might wanna change the current network helpers setup a bit once the changes to codec-sv2, maybe then I will add the test.

@bit-aloo
bit-aloo requested a review from GitGab19 August 11, 2026 09:56
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.

2 participants