Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
mpc = {path = "../mpc"}
vm = {path = "../vm"}
tokio = {version = "0.2", features = ["full"] }
6 changes: 6 additions & 0 deletions player/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use mpc::protocols::{honey_badger::HoneyBadgerMPC, MPCProtocol};
use vm::processor::arithmetic::ArithmeticCore;
use vm::processor::Processor;
use vm::StoffelVM;
use vm::Program;
use tokio::net::{TcpListener, TcpStream};

pub struct Player<T: MPCProtocol, U: Processor> {
id: String,
Expand All @@ -23,6 +25,10 @@ impl<T: MPCProtocol, U: Processor> Player<T, U> {
fn broadcast_and_receive() -> Result<(), Box<dyn std::error::Error>> {
todo!();
}

pub async fn run(program: Program<U>, listener: TcpListener) -> Result<(), Box<dyn std::error::Error>> {
todo!();
}
}

// example to instantiate a specific Player
Expand Down
59 changes: 8 additions & 51 deletions types/src/vm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,12 @@
use std::ops::{Add, Mul};

pub mod ark;
pub mod number;

/// This trait is a catch-all for a type that is used
/// within the virtual machine
pub trait Number:
Add<Output = Self> + Mul<Output = Self> + Copy + Default + std::fmt::Debug + Sized + 'static
{
/// Add two numbers
///
/// Use the implementation provided by the implementor
fn add(self, b: Self) -> Self {
Add::add(self, b)
}

/// Multiply two numbers
///
/// Use the implementation provided by the implementor
fn mul(self, b: Self) -> Self {
Mul::mul(self, b)
}

/// Returns the square of an MPCType
fn square(self) -> Self {
todo!();
}

/// Returns the power of itself to an exponent
fn pow(self, exp: usize) -> Self {
todo!();
}

/// Returns the minimum between itself and another MPCType
fn min(self, a: Self) -> Self {
todo!();
}

/// Returns the maximum between itself and another MPCType
fn max(self, b: Self) -> Self {
todo!();
}

/// Returns a if self == 1 and b if self == 0
fn if_else(self, a: Self, b: Self) -> Self {
todo!();
}
pub use ark::*;
pub use number::*;

/// Returns (a, b) if self == 0 and (b, a) if self == 1
fn cond_swap(self, a: Self, b: Self) -> (Self, Self) {
todo!();
}
}
/// Register address type for indicating which register to use
pub type RegisterAddr = usize;

impl Number for u32 {}
/// Immediate value type for clear values
/// TODO: Change this to be of a specific Number type instead of u64
pub type ImmediateValue = u64;
53 changes: 53 additions & 0 deletions types/src/vm/number.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::ops::{Add, Mul};

/// This trait is a catch-all for a type that is used
/// within the virtual machine
pub trait Number:
Add<Output = Self> + Mul<Output = Self> + Copy + Default + std::fmt::Debug + Sized + 'static
{
/// Add two numbers
///
/// Use the implementation provided by the implementor
fn add(self, b: Self) -> Self {
Add::add(self, b)
}

/// Multiply two numbers
///
/// Use the implementation provided by the implementor
fn mul(self, b: Self) -> Self {
Mul::mul(self, b)
}

/// Returns the square of an MPCType
fn square(self) -> Self {
todo!();
}

/// Returns the power of itself to an exponent
fn pow(self, exp: usize) -> Self {
todo!();
}

/// Returns the minimum between itself and another MPCType
fn min(self, a: Self) -> Self {
todo!();
}

/// Returns the maximum between itself and another MPCType
fn max(self, b: Self) -> Self {
todo!();
}

/// Returns a if self == 1 and b if self == 0
fn if_else(self, a: Self, b: Self) -> Self {
todo!();
}

/// Returns (a, b) if self == 0 and (b, a) if self == 1
fn cond_swap(self, a: Self, b: Self) -> (Self, Self) {
todo!();
}
}

impl Number for u32 {}
11 changes: 6 additions & 5 deletions vm/src/instructions/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use crate::processor::arithmetic::ArithmeticCore;
use mpc::protocols::MPCProtocol;

// Assign immediate value to clear register
pub fn ldi<T: MPCProtocol>(processor: &mut ArithmeticCore<T>) {
todo!();
/// Assign immediate value to clear register
pub fn ldi<T: MPCProtocol>(processor: &mut ArithmeticCore<T>, register_pos: usize, immediate_value: T::VmType) {
// TODO: Add error handling and a return type for successful execution
processor.public_register.write(register_pos, immediate_value);
}

// Assign immeidate value to secret register
/// Assign immeidate value to secret register
pub fn ldsi<T: MPCProtocol>(processor: &mut ArithmeticCore<T>) {
todo!();
}

// Assign clear register to clear memory value(s) by immediate address
/// Assign clear register to clear memory value(s) by immediate address
pub fn stmc<T: MPCProtocol>(processor: &mut ArithmeticCore<T>) {
todo!();
}
Expand Down
33 changes: 33 additions & 0 deletions vm/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,36 @@ pub mod arithmetic;
pub mod boolean;
pub mod common;
pub mod opcodes;

use opcodes::{Opcode, InstructionOpcode};
use types::vm::{RegisterAddr, ImmediateValue};
use super::processor::Processor;

#[derive(Debug)]
pub struct Instruction<P: Processor> {
opcode: Opcode,
opcode_name: InstructionOpcode,
processor: P,
vector_size: usize,
instruction_register1: RegisterAddr,
instruction_register2: RegisterAddr,
instruction_register3: RegisterAddr,
instruction_register4: RegisterAddr,
possible_immediate_value: ImmediateValue,
// TODO: Change u64 to appropriate mpc type
variable_params: Vec<u64>
}

impl<P: Processor> Instruction<P> {
pub fn new() -> Self {
todo!();
}

pub fn parse(&mut self) -> Result<(),Box<dyn std::error::Error>>{
todo!();
}

pub fn execute() -> Result<(), Box<dyn std::error::Error>> {
todo!();
}
}
Loading