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: garble vm #191

Merged
merged 4 commits into from
Nov 9, 2024
Merged

feat: garble vm #191

merged 4 commits into from
Nov 9, 2024

Conversation

sinui0
Copy link
Collaborator

@sinui0 sinui0 commented Nov 3, 2024

This PR implements a semi-honest GC VM, including a lot of the core functionality which can be applied to implement the coming quicksilver VM.

@sinui0 sinui0 requested review from themighty1 and th4s November 3, 2024 20:41
This was referenced Nov 3, 2024
Copy link
Member

@th4s th4s left a comment

Choose a reason for hiding this comment

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

looking good, nice abstractions 🚀 🚀

crates/mpz-memory-core/src/correlated/macs.rs Show resolved Hide resolved
crates/mpz-garble-core/src/generator.rs Outdated Show resolved Hide resolved
crates/mpz-garble-core/src/lib.rs Outdated Show resolved Hide resolved
crates/mpz-garble-core/src/view.rs Show resolved Hide resolved
@sinui0 sinui0 merged commit 50828d7 into alpha.1 Nov 9, 2024
@sinui0 sinui0 deleted the feat/garble-vm branch November 9, 2024 06:37
Copy link
Collaborator

@themighty1 themighty1 left a comment

Choose a reason for hiding this comment

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

Good work.
I left some qs, including security-critical ones.
@sinui0

R: Send + 'static,
W: Fn(&T) -> usize + Send + 'static,
{
let item_count = items.len();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to return an early error here if item_count == 0 ?

@@ -200,6 +222,27 @@ impl<Io> MTContext<Io> {
.first()
.expect("child thread should be available"))
}

async fn get_children(&mut self, count: usize) -> Result<&[Handle<Self>], ContextError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this fn allowed to return more children than count? If so, could we add a comment, otherwise such behaviour looks like an error.

//
// Only prove MACs for output data and evaluator's inputs.
let provable_input = match self.role {
Role::Generator => input - self.vis.visible(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why this not input.intersection(self.vis.blind()) like above?

idx_outputs |= output.to_range();
true
} else {
false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we also do
idx_outputs |= output.to_range();
before returning false?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, makes sense and I tested it. Without this fix the vm preprocess call hangs. With this fix it proceeds.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please open a PR if you've identified a fix for a bug

Copy link
Member

Choose a reason for hiding this comment

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

included in #197

.scope_boxed()
});

while !self.call_stack.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the loop will end up draining the entire callstack, what is the purpose of receiving the garbled circuits layer-by-layer? We can just receive the garbled circuits for the entirety of the callstack in one go.

Copy link
Collaborator Author

@sinui0 sinui0 Dec 13, 2024

Choose a reason for hiding this comment

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

It's because we process them in parallel and this ensures no interdependencies to facilitate that. The generator is streaming the gates over separate IO threads

});
}

let expected = hasher.tccr(Block::from((id as u128).to_be_bytes()), *mac.as_block());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should use a strong hash here. Fixed-key AES TCCR was not proven to have strong hash properties like e.g. collision resistance.


/// Adjusts the truth value of the corresponding MAC.
#[inline]
pub fn adjust(&mut self, adjust: bool, delta: &Delta) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had a hard time parsing what this method tries to achieve. Could you describe the adjust argument?

#[inline]
pub fn new(delta: Delta) -> Self {
let mut public_one = Key(MAC_ONE ^ delta.as_block());
public_one.0.set_lsb(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

iiuc, at this point the LSB will always be 0, why do we need to set it here?
MAC_ONE's LSB is always 1, delta's LSB is always 1 and so the Key's LSB will always be zero.


/// Allocates memory with the given keys.
///
/// The provided keys are marked as used.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The keys are not marked as used here.

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.

3 participants