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

feat: make encryption per partition instead of per message #107

Merged
merged 14 commits into from
Jan 22, 2025

Conversation

ChaoticTempest
Copy link
Contributor

  • make encryption sent to other nodes be per request/partition now instead of each message, so from send(Partition = Vec<Ciphered>) to send(Partition = Ciphered(Vec<Message>)) is the effective change.
  • internalize message decryption to the MessageInbox such that when nodes call send to other nodes, there's no wait for the response due to all the decryption that is happening.
  • optimize serialization of SignMessage. json serialization is very inefficient, especially for byte vectors, so bincode is used to get away from all that json overhead. bincode is for the most part just raw byte serialization.
  • some cleanup of error variants that were no longer useful or being used.

@ChaoticTempest ChaoticTempest linked an issue Jan 15, 2025 that may be closed by this pull request
ppca
ppca previously approved these changes Jan 15, 2025
Copy link
Contributor

@ppca ppca left a comment

Choose a reason for hiding this comment

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

LGTM!

chain-signatures/node/src/protocol/cryptography.rs Outdated Show resolved Hide resolved
@ChaoticTempest ChaoticTempest force-pushed the phuong/feat/less-encryption branch 2 times, most recently from fd38ec2 to df8b908 Compare January 16, 2025 06:56
Copy link

@jakmeier jakmeier left a comment

Choose a reason for hiding this comment

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

Hey, I noticed you want to introduce bincode on the wire, so I left my thought on it.

(It might also make sense to have the format change in a separate PR from "make encryption per partition instead of per message" .)

})?;
let SignedMessage::<Vec<u8>> { msg, sig, from } = serde_json::from_slice(&message)?;
let Self { msg, sig, from } = bincode::deserialize(&msg).unwrap();

Choose a reason for hiding this comment

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

I would be careful with this change.

Unlike JSON, bincode is not self-describing. In other words, it does not encode field information. Instead, you must use the exact same struct for serialization and deserialization. If anything in the serialized type changes, for example you add a new field to a variant of MpcMessage, this may break deserialization. This manifests as either an explicit deserialization error or, if it cannot detect a mismatchmaybe, it just silently deserializes invalid data.

For non-distributed systems, this is usually not a problem.
But you have to consider that nodes will not update all at the same time. Hence, there will be times where different versions of a struct like MpcMessage are used in the system. You should be able to handle this gracefully.

Typically, one either uses a format that allows dynamic changes, like JSON or protobuf. Then you can add new fields or make old fields optional, without breaking anything. If you use something like bincode, however, it requires manual versioning, which can be a bit painful.

If you are looking for an easy JSON replacement but with binary encoding, take a look at CBOR, it is supported with serde: https://github.com/enarx/ciborium

Long term, it might make sense to think about using something like protobuf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, yeah that's a good point. I'll change it to CBOR in this PR

(It might also make sense to have the format change in a separate PR from "make encryption per partition instead of per message" .)

the reason why it's a part of this PR is because changing from Partition = Vec<Encrypted> to Partition = Encrypted breaks some things due to how json serialization works, like how serializing a bundle of messages would more than increase its size up to 10x what it was before. This was easy to check before when we encrypted per message and summed them up before partitioning them, but since partition now happens before encryption, things aren't as well

@ChaoticTempest ChaoticTempest force-pushed the phuong/feat/less-encryption branch from df8b908 to eb18367 Compare January 16, 2025 07:56
@ChaoticTempest ChaoticTempest force-pushed the phuong/feat/less-encryption branch from ea05873 to e69ab91 Compare January 17, 2025 21:03
@ChaoticTempest
Copy link
Contributor Author

Moved to ciborium for cbor encoding. Also added unit tests for serialization changes. So our Messages are now future and backwards compatible

chain-signatures/keys/src/hpke.rs Outdated Show resolved Hide resolved
chain-signatures/node/src/protocol/message.rs Show resolved Hide resolved
use crate::actions::sign::SignAction;
use crate::actions::wait::WaitAction;

pub fn spawn() -> ClusterSpawner {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these deletions relevant? Are they intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these were mistakenly committed. Look at the folder structure

@volovyks volovyks linked an issue Jan 21, 2025 that may be closed by this pull request
volovyks
volovyks previously approved these changes Jan 21, 2025
@ChaoticTempest ChaoticTempest merged commit 6d14c31 into develop Jan 22, 2025
2 of 3 checks passed
@ChaoticTempest ChaoticTempest deleted the phuong/feat/less-encryption branch January 22, 2025 15:49
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.

Encrypt and sign messages in batches Write a test that checks for breaking changes in serialization format
4 participants