Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgwiese committed Oct 31, 2023
1 parent be921fd commit a8daee5
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compiler/tests/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,24 @@ fn vm_to_vm_dynamic_trace_length() {
gen_estark_proof(f, slice_to_vec(&i));
}

#[test]
fn vm_to_vm_to_block() {
let f = "vm_to_vm_to_block.asm";
let i = [];
verify_asm::<GoldilocksField>(f, slice_to_vec(&i));
gen_halo2_proof(f, slice_to_vec(&i));
gen_estark_proof(f, slice_to_vec(&i));
}

#[test]
fn vm_to_vm_to_vm() {
let f = "vm_to_vm_to_vm.asm";
let i = [];
verify_asm::<GoldilocksField>(f, slice_to_vec(&i));
gen_halo2_proof(f, slice_to_vec(&i));
gen_estark_proof(f, slice_to_vec(&i));
}

#[test]
fn test_mem_read_write() {
let f = "mem_read_write.asm";
Expand Down
66 changes: 66 additions & 0 deletions test_data/asm/vm_to_vm_to_block.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
machine Main {

degree 256;

Pythagoras pythagoras;

reg pc[@pc];
reg X[<=];
reg Y[<=];
reg Z[<=];
reg A;

instr pythagoras X, Y -> Z = pythagoras.pythagoras
instr assert_eq X, Y { X = Y }

function main {
A <== pythagoras(3, 4);
assert_eq A, 25;

A <== pythagoras(4, 3);
assert_eq A, 25;

A <== pythagoras(1, 2);
assert_eq A, 5;

return;
}
}


machine Pythagoras {

Arith arith;

reg pc[@pc];
reg X[<=];
reg Y[<=];
reg Z[<=];
reg A;
reg B;


instr add X, Y -> Z = arith.add
instr mul X, Y -> Z = arith.mul

function pythagoras a: field, b: field -> field {
A <== mul(a, a);
B <== mul(b, b);
A <== add(A, B);
return A;
}
}

machine Arith(latch, operation_id) {

operation add<0> x1, x2 -> y;
operation mul<1> x1, x2 -> y;

col fixed latch = [1]*;
col witness operation_id;
col witness x1;
col witness x2;
col witness y;

y = operation_id * (x1 * x2) + (1 - operation_id) * (x1 + x2);
}
73 changes: 73 additions & 0 deletions test_data/asm/vm_to_vm_to_vm.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
machine Main {

degree 256;

Pythagoras pythagoras;

reg pc[@pc];
reg X[<=];
reg Y[<=];
reg Z[<=];
reg A;

instr pythagoras X, Y -> Z = pythagoras.pythagoras
instr assert_eq X, Y { X = Y }

function main {
A <== pythagoras(3, 4);
assert_eq A, 25;

A <== pythagoras(4, 3);
assert_eq A, 25;

A <== pythagoras(1, 2);
assert_eq A, 5;

return;
}
}

machine Pythagoras {

Arith arith;

reg pc[@pc];
reg X[<=];
reg Y[<=];
reg Z[<=];
reg A;
reg B;


instr add X, Y -> Z = arith.add
instr mul X, Y -> Z = arith.mul

function pythagoras a: field, b: field -> field {
A <== mul(a, a);
B <== mul(b, b);
A <== add(A, B);
return A;
}
}

machine Arith {

reg pc[@pc];
reg X[<=];
reg Y[<=];
reg Z[<=];
reg A;

instr add X, Y -> Z { X + Y = Z }
instr mul X, Y -> Z { X * Y = Z }

function add x: field, y: field -> field {
A <== add(x, y);
return A;
}

function mul x: field, y: field -> field {
A <== mul(x, y);
return A;
}
}

0 comments on commit a8daee5

Please sign in to comment.