Skip to content

Commit

Permalink
feat: witness creation for plain vm (#37)
Browse files Browse the repository at this point in the history
* eagerly sub comp running
* plain vm now builds witness, also added some tests
* started clean up
* functions are now really functions and not baby components
* some clean up and correct eddsa test
  • Loading branch information
0xThemis authored May 28, 2024
1 parent c110142 commit 45f8cfa
Show file tree
Hide file tree
Showing 16 changed files with 983 additions and 813 deletions.
685 changes: 0 additions & 685 deletions collaborative-groth16/src/vm.rs

This file was deleted.

448 changes: 320 additions & 128 deletions collaborative-groth16/src/vm/compiler.rs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions collaborative-groth16/src/vm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod compiler;
mod op_codes;
pub mod plain_vm;
mod stack;
100 changes: 100 additions & 0 deletions collaborative-groth16/src/vm/op_codes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
pub type CodeBlock = Vec<MpcOpCode>;
#[derive(Clone)]
pub enum MpcOpCode {
PushConstant(usize),
PushIndex(usize),
LoadSignal,
StoreSignal,
LoadVar,
StoreVars,
StoreVar,
OutputSubComp(bool, usize),
InputSubComp(bool, usize),
CreateCmp(String, usize), //what else do we need?
Call(String, usize),
Return,
ReturnFun,
Assert,
Add,
Sub,
Mul,
Div,
IntDiv,
Neg,
Lt,
Le,
Gt,
Ge,
Eq,
Neq,
BoolOr,
BoolAnd,
BitOr,
BitAnd,
BitXOr,
ShiftR,
ShiftL,
MulIndex,
AddIndex,
ToIndex,
Jump(usize),
JumpBack(usize),
JumpIfFalse(usize),
Log(usize, usize),
}

impl std::fmt::Display for MpcOpCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let string = match self {
MpcOpCode::PushConstant(constant_index) => {
format!("PUSH_CONSTANT_OP {}", constant_index)
}
MpcOpCode::PushIndex(index) => format!("PUSH_INDEX_OP {}", index),
MpcOpCode::LoadSignal => "LOAD_SIGNAL_OP".to_owned(),
MpcOpCode::StoreSignal => "STORE_SIGNAL_OP".to_owned(),
MpcOpCode::LoadVar => "LOAD_VAR_OP".to_owned(),
MpcOpCode::StoreVar => "STORE_VAR_OP".to_owned(),
MpcOpCode::StoreVars => "STORE_VARS_OP".to_owned(),
MpcOpCode::Call(symbol, return_vals) => {
format!("CALL_OP {symbol} {return_vals}")
}
MpcOpCode::CreateCmp(header, amount) => format!("CREATE_CMP_OP {} [{amount}]", header),
MpcOpCode::Assert => "ASSERT_OP".to_owned(),
MpcOpCode::Add => "ADD_OP".to_owned(),
MpcOpCode::Sub => "SUB_OP".to_owned(),
MpcOpCode::Mul => "MUL_OP".to_owned(),
MpcOpCode::Div => "DIV_OP".to_owned(),
MpcOpCode::IntDiv => "INT_DIV_OP".to_owned(),
MpcOpCode::Neg => "NEG_OP".to_owned(),
MpcOpCode::Lt => "LESS_THAN_OP".to_owned(),
MpcOpCode::Le => "LESS_EQ_OP".to_owned(),
MpcOpCode::Gt => "GREATER_THAN_OP".to_owned(),
MpcOpCode::Ge => "GREATER_EQ_OP".to_owned(),
MpcOpCode::Eq => "IS_EQUAL_OP".to_owned(),
MpcOpCode::Neq => "NOT_EQUAL_OP".to_owned(),
MpcOpCode::BoolOr => "BOOL_OR_OP".to_owned(),
MpcOpCode::BoolAnd => "BOOL_AND_OP".to_owned(),
MpcOpCode::BitOr => "BIT_OR_OP".to_owned(),
MpcOpCode::BitAnd => "BIT_AND_OP".to_owned(),
MpcOpCode::BitXOr => "BIT_XOR_OP".to_owned(),
MpcOpCode::ShiftR => "RIGHT_SHIFT_OP".to_owned(),
MpcOpCode::ShiftL => "LEFT_SHIFT_OP".to_owned(),
MpcOpCode::AddIndex => "ADD_INDEX_OP".to_owned(),
MpcOpCode::MulIndex => "MUL_INDEX_OP".to_owned(),
MpcOpCode::ToIndex => "TO_INDEX_OP".to_owned(),
MpcOpCode::Jump(line) => format!("JUMP_OP {line}"),
MpcOpCode::JumpBack(line) => format!("JUMP_BACK_OP {line}"),
MpcOpCode::JumpIfFalse(line) => format!("JUMP_IF_FALSE_OP {line}"),
MpcOpCode::Return => "RETURN_OP".to_owned(),
MpcOpCode::ReturnFun => "RETURN_FUN_OP".to_owned(),
MpcOpCode::OutputSubComp(mapped, signal_code) => {
format!("OUTPUT_SUB_COMP_OP {mapped} {signal_code}")
}
MpcOpCode::InputSubComp(mapped, signal_code) => {
format!("INPUT_SUB_COMP_OP {mapped} {signal_code}")
}
MpcOpCode::Log(line, amount) => format!("LOG {line} {amount}"),
};
f.write_str(&string)
}
}
Loading

0 comments on commit 45f8cfa

Please sign in to comment.